import pymysql


class DBConnection(object):
    # conn = None
    def __init__(self,*args):
        self.conn = pymysql.connect(
            host='localhost',  # 服务器所在地址
            port=3306,  # 端口号
            user='root',
            password='123456',
            db='mydb'
        )

    def getCursor(self):
        cursor = self.conn.cursor(cursor=pymysql.cursors.DictCursor)
        return cursor

    def add_row(self, person,cursor):#插入
        sql = "insert into person(pno,name,age,address) values({0},'{1}',{2},'{3}')".format(person.pno,person.name,person.age,person.address)
        # with self.getCursor() as cursor:
        cursor.execute(sql)
        self.conn.commit()



